/////////////////////////////////////////////////////////////////////////
//
// Amuse Engine SDK - core/math/types/Sse
// Copyright (c) 2014.  All Rights Reserved
//
// File:		AESseMathTypes.h
// Author:		Gianluca Belardelli
// Date:		07/01/2014
//
/////////////////////////////////////////////////////////////////////////
#ifndef _AESSEMATHTYPES_H_
#define _AESSEMATHTYPES_H_

// include SSE
#include <xmmintrin.h>

#if AE_SSE_VERSION >= 0x20
#include <emmintrin.h>
#endif

#if AE_SSE_VERSION >= 0x30
#include <pmmintrin.h>
#endif

#if AE_SSE_VERSION >= 0x31
#include <tmmintrin.h>
#endif

#if AE_SSE_VERSION >= 0x40
#include <wmmintrin.h>
#endif

#if AE_SSE_VERSION >= 0x41
#include <smmintrin.h>
#endif

#if AE_SSE_VERSION >= 0x42
#include <nmmintrin.h>
#endif

#if AE_SSE_VERSION >= 0x50
#include <immintrin.h>
#endif

#if defined(AE_ARCH_X64) && defined(AE_COMPILER_MSVC) && ( _MSC_VER >= 1700)
#	include <intrin.h>
#endif

// storage type for hkVector4 (and thus hkQuaternion)
typedef __m128 AEQuadFloat32;

// storage type for hkSimdReal
typedef __m128 AESingleFloat32;

#if AE_SSE_VERSION >= 0x50
	typedef __m256d AEQuadDouble64;
#else
	struct AEQuadDouble64
	{
		__m128d xy;
		__m128d zw;
	};
#endif

#define AE_VECTORTRANSPOSE4F(A,B,C,D) _MM_TRANSPOSE4_PS( A.m_qfVector,B.m_qfVector,C.m_qfVector,D.m_qfVector )

#define AE_VECTORTRANSPOSE3F(_a,_b,_c) { \
	const AEQuadFloat32 _tmp = _mm_unpacklo_ps( _a.m_qfVector,_b.m_qfVector ); \
	const AEQuadFloat32 _ctmp = _mm_shuffle_ps( _mm_unpackhi_ps( _a.m_qfVector, _b.m_qfVector ), _c.m_qfVector, _MM_SHUFFLE( 3, 2, 1, 0 ) ); \
	_a.m_qfVector = _mm_movelh_ps( _tmp, _c.m_qfVector ); \
	_b.m_qfVector = _mm_shuffle_ps( _mm_movehl_ps( _a.m_qfVector, _tmp ), _c.m_qfVector, _MM_SHUFFLE( 3, 1, 1, 0 ) ); \
	_c.m_qfVector = _ctmp; }

// storage type for AEVector4Comparison
typedef __m128 AEVector4fMask;

class AEVector4f;
typedef const AEVector4f &AEVector4fRefParam;

class AESimdFloat32;
typedef const AESimdFloat32 &AESimdFloat32ConstRef;

class AEVector4fComparison;
typedef const AEVector4fComparison &AEVector4fConstRefCompParam;

#endif // _AESSEMATHTYPES_H_
